home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / OpalDev.lha / Examples / displaydir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-01  |  3.7 KB  |  167 lines

  1. #define OPAL_PRIVATE
  2. #include "opal/opallib.h"
  3. #include <exec/memory.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7.  
  8. #ifndef    AZTEC_C
  9. #include <proto/all.h>
  10. #endif
  11.  
  12. struct OpalBase *OpalBase;
  13. struct OpalScreen *OScrn;
  14.  
  15. BOOL Display_Directory (char *Path);
  16. char *Make_FileName (char *Path,char *FileName);
  17. long OldOSFlags;
  18. long OldUpdCount;
  19.  
  20. #define AND &&
  21. #define OR ||
  22.  
  23. #define TNWIDTH     48        /* Multiply this by 2 for hires */
  24. #define TNLINES  30        /* Multiply this by 2 for interlace */
  25. #define XSPACING 10        /* Multiply this by 2 for hires */
  26. #define YSPACING 5        /* Multiply this by 2 for interlace */
  27. #define XSTART 20
  28. #define YSTART 6
  29.  
  30.  
  31. BOOL Display_Directory (char *Path);
  32. char *Make_FileName (char *Path,char *FileName);
  33. void Set_Lores (int Top,int Lines);
  34. void Restore_Res (void);
  35.  
  36.  
  37. void main (int argc,char *argv[])
  38. {
  39.  
  40.     if (argc!=2)
  41.         { puts ("Usage: DisplayDir Directory\n");
  42.           exit (0);
  43.         }
  44.  
  45.     OpalBase = (struct OpalBase *) OpenLibrary ("opal.library",0L);
  46.     if (OpalBase==NULL)
  47.         { puts ("Can't open opal.library\n");
  48.           exit (0);
  49.         }
  50.  
  51.     OScrn = OpenScreen24 (0);
  52.     if (OScrn!=NULL)
  53.         { Display_Directory (argv[1]);
  54.           Refresh24();
  55.           AutoSync24 (TRUE);
  56.           Delay (150L);
  57.           CloseScreen24 ();
  58.         }
  59.     CloseLibrary ((struct Library *)OpalBase);
  60. }
  61.  
  62.  
  63. BOOL Display_Directory (char *Path)
  64. {
  65.    struct FileLock *FL;
  66.    struct FileInfoBlock *FIB;
  67.    register int x,y;
  68.    long Error;
  69.    BOOL Aborted;
  70.    char *Name;
  71.  
  72.  
  73.     FIB = AllocMem ((long)sizeof(struct FileInfoBlock),MEMF_CLEAR);
  74.     if (FIB==NULL)
  75.         return (FALSE);
  76.  
  77.     FL = (struct FileLock *) Lock (Path,ACCESS_READ);
  78.     if (FL==NULL)
  79.         { printf ("Couldn't open Directory !!");
  80.           FreeMem (FIB,(long)sizeof(struct FileInfoBlock));
  81.           return (FALSE);
  82.         }
  83.  
  84.     x = XSTART;
  85.     y = YSTART;
  86.     Aborted = FALSE;
  87.     Examine ((BPTR)FL,FIB);
  88.     Error = 0;
  89.     if (ExNext ((BPTR)FL,FIB)==NULL)
  90.         Error = IoErr();
  91.     while ((Error!=ERROR_NO_MORE_ENTRIES) AND (!Aborted))
  92.         { Name = Make_FileName (Path,FIB->fib_FileName);
  93.           if (DisplayThumbnail24 (OScrn,Name,x,y)==0)
  94.             { x = x + TNWIDTH + XSPACING;
  95.               if (x+TNWIDTH>OScrn->Width)
  96.                 { x = XSTART;
  97.                   y = y + TNLINES+YSPACING;
  98.                   if (y+TNLINES>OScrn->Height) Aborted = TRUE;
  99.                 }
  100.             }
  101.           if (ExNext ((BPTR)FL,FIB)==NULL)
  102.             Error = IoErr();
  103.           }
  104.  
  105.     UnLock ((BPTR)FL);
  106.     FreeMem (FIB,(long)sizeof(struct FileInfoBlock));
  107.     return (TRUE);
  108. }
  109.  
  110. char TempStr[200];
  111.  
  112. char *Make_FileName (char *Path,char *FileName)
  113. {
  114.    register int i;
  115.  
  116.     strcpy (TempStr,Path);
  117.     i = strlen (TempStr);
  118.     if ((i!=0) AND (TempStr[i-1]!=':'))
  119.         strcat (TempStr,"/");
  120.     strcat (TempStr,FileName);
  121.     return (TempStr);
  122. }
  123.  
  124.  
  125. /*  The following routines are useful for displaying
  126.  * thumbnails in hires/interlaces screens. Thumbnails
  127.  * are always lores non-interlace, so to get around this
  128.  * the following routine sets a number of lines into lo-res
  129.  * mode, and clears the field bit in the control line of the
  130.  * odd NODMA copper list. This forces both fields to display
  131.  * the same lines. The thumbnails will then be displayed 
  132.  * correctly.
  133.  */
  134.  
  135. void Set_Lores (int Top,int Lines)
  136. {
  137.   register int i;
  138.  
  139.     OldOSFlags = OScrn->Flags;
  140.     OldUpdCount = OScrn->Update_Cycles;
  141.  
  142.     OScrn->Flags &= ~(HIRES24|ILACE24);
  143.     OScrn->Update_Cycles = 3;
  144.     if (OldOSFlags & HIRES24)
  145.         { for (i=Top; (i<Top+Lines) AND (i<OScrn->LastCoProIns); i++)
  146.             OScrn->CoProData[i+OScrn->CoProOffset] &= (~HIRESDISP);
  147.           UpdateCoPro24();
  148.         }
  149.     if (OldOSFlags & ILACE24)
  150.         SetControlBit24 (13L,11L,0L);      /* Display field 0 */
  151. }
  152.  
  153. void Restore_Res (void)
  154. {
  155.    register int i;
  156.  
  157.     OScrn->Flags = OldOSFlags;
  158.     OScrn->Update_Cycles = OldUpdCount;
  159.     if (OldOSFlags & HIRES24)
  160.         { for (i=0; i<OScrn->LastCoProIns; i++)
  161.             OScrn->CoProData[i+OScrn->CoProOffset] |= HIRESDISP;
  162.           UpdateCoPro24();
  163.         }
  164.     if (OldOSFlags & ILACE24)
  165.         SetControlBit24 (13L,11L,1L);    /* Restore field 1 display */
  166. }
  167.